package com.xiaoxu.yihaoShop.PVJob;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


public class PVApp {

    public static void main(String[] args) throws Exception{

        Configuration configuration = new Configuration();

        FileSystem fileSystem = FileSystem.get(configuration);

        Path outputPath = new Path("data/output/pv/");

        if (fileSystem.exists(outputPath)){
            fileSystem.delete(outputPath,true);
            System.out.println("输出结果已被删除");
        }

        Job job = Job.getInstance(configuration);

        job.setJarByClass(PVApp.class);

        job.setMapperClass(PVMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);

        job.setReducerClass(PVReduce.class);
        job.setOutputKeyClass(NullWritable.class);
        job.setMapOutputValueClass(LongWritable.class);

        FileInputFormat.setInputPaths(job,new Path("data/output/etl/part-r-00000"));
        FileOutputFormat.setOutputPath(job,outputPath);

        job.waitForCompletion(true);


    }

}
